﻿@{
    ViewBag.Title = "List";
    Layout = "~/Views/Shared/_PageLayout.cshtml";
}
@model Beway.ValueAdded.Model.ReUser
@section HeadSection
{ 
    <script type="text/javascript">
        var role = "@Session["role"]";
        var url = "";
        $(function () {
            $('#ReUserList').datagrid({
                title: '项目成本优化',
                iconCls: 'icon-edit',
                url: '/Discount/ReUserList',
                striped: true,
                idField: 'UserID',
                border: true,
                loadMsg: '数据加载中...',
                singleSelect: true,
                pagination: true,
                pageSize: 20,
                pageList: [15, 20],                 
                columns: [[
                    { field: 'UserID', title: '项目ID', width: 50, align: 'center' },
                        { field: 'UserTitle', title: '项目名称', width: 200 },
                        { field: 'AdminTrueName', title: '项目经理', width: 80, align: 'center' },
                        { field: 'AdminMobile', title: '项目经理手机', width: 90, align: 'center' },
                        { field: 'AdminId', title: '项目经理', width: 0, align: 'center', hidden: true },                        
                         {
                             field: 'RechStatus', title: '账户状态', width: 70, align: 'center', formatter: function (val, rec) {
                                 if (val == 1) {
                                     return "<font style='color:green;'>启用</font>";
                                 }
                                 else {
                                     return "<font style='color:red;'>禁用</font>";
                                 }
                             }
                         },
                         {
                             field: 'BeginTime', title: '项目时间', width: 240, align: 'center', formatter: function (v, rec) {
                                 return JSONDateToJSDate(v) + ' - ' + JSONDateToJSDate(rec.EndTime);

                             }
                         },
                          { field: 'RechAmount', title: '剩余/总预算(元)', width:110, align: 'center', formatter:function(val,rec){
                              return "<span style='color:green;'>"+rec.RechStock+"</span>/<span style='color:red'>"+val+"</span>";
                          } },
                          {
                              field: 'RechDiscountRate', title: '扣量率(%)', width: 80, align: 'center', formatter: function (val) {
                                  return "<span style='color:red'>"+val+"</span>";
                              }
                          },
                         
                        {
                            field: 'tel', title: '统计报表', width: 220, align: 'center', formatter: function (val, rec) {
                                return '<a href="/Report/ReportDetail?rcType=1&userId=' + rec.UserID + '&userTitle=' + rec.UserTitle + '">话费</a>&nbsp;&nbsp;' +
                                    '<a href="/Report/ReportDetail?rcType=2&userId=' + rec.UserID + '&userTitle=' + rec.UserTitle + '">Q币</a>&nbsp;&nbsp;' +
                                        '<a href="/Report/ReportDetail?rcType=3&userId=' + rec.UserID + '&userTitle=' + rec.UserTitle + '">礼品卡</a>&nbsp;&nbsp;' +
                                     '<a href="/Report/ReportDetail?rcType=4&userId=' + rec.UserID + '&userTitle=' + rec.UserTitle + '">流量包</a>&nbsp;&nbsp;'+
                                    '<a href="/Report/ReportDetail?rcType=5&userId=' + rec.UserID + '&userTitle=' + rec.UserTitle + '">微信红包</a>';
                            }
                        }
                ]], toolbar: [{
                    text: '编辑扣量率',
                    iconCls: 'icon-edit',
                    handler: function () {
                        editReUser();
                    }
                }, '-']

            });

            //尺寸
            $('#ReUserList').datagrid('resize');

            //加载搜索框//在这个样式下。加载搜索框的div
            $(".datagrid-toolbar").append($("#divsearch"));
            
        });

        //搜索
        function doSearch() {
            $('#ReUserList').datagrid('load', { UserName: $("#UserName").val() });
        }

     
        //新增确定
        function ReUserSave() {
            $.messager.progress();
            $("#fm").form('submit', {
                url: url,
                onSubmit: function () {
                    if (!$(this).form('validate')) {
                        $.messager.progress('close');
                        return false;
                    }
                },
                success: function (result) {
                    $.messager.progress('close');
                    if (result > 0) {
                        $("#dlg").dialog('close');
                        $.messager.alert('提示', '信息保存成功');
                        $("#ReUserList").datagrid('reload');
                    } else if (result == -5) {
                        $.messager.show({
                            title: 'Error',
                            msg: "该用户名已经存在"
                        }
                        );
                    }
                    else {
                        $.messager.show({
                            title: 'Error',
                            msg: "保存信息失败"
                        }
                        );
                    }
                }
            });
        }
        //编辑
        function editReUser() {
            var row = $("#ReUserList").datagrid('getSelected');
            if (row) {
                $("#dlg").dialog('open').dialog('setTitle', '编辑充值项目');              

                $('#BeginTime').datetimebox('setValue', JSONDateToJSDate(row.BeginTime));
                $('#EndTime').datetimebox('setValue', JSONDateToJSDate(row.EndTime));                

                $("#fm").form('load', row);

                url = "/Discount/UpdateReUser";

                $("#UserTitle").html(row.UserTitle);                
                
            } else {

                $.messager.alert('提示', '请选择数据行进行编辑!');
            }
        }        
    </script>
}
<div id="divsearch">
    项目名称：<input type="text" name="UserName" id="UserName" style="width: 80px" />
    <a href="#" class="easyui-linkbutton" onclick="doSearch();" iconcls="icon-search">搜索</a>
</div>
<table id="ReUserList" toolbar="#divsearch">
</table>
<div id="dlg-buttons">
    <a href="#" class="easyui-linkbutton" iconcls="icon-ok" onclick="ReUserSave()">保存</a>
    <a href="#" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>
<div id="dlg" class="easyui-dialog" style="width: 800px; padding: 10px 10px" resizable="true"
    closed="true" modal="true" buttons="#dlg-buttons">
    <form id="fm" method="post" enctype="multipart/form-data">
        <div class="fitem">
            <label>项目名称：</label>
            <span id="UserTitle"></span>
        </div>       
        <div class="fitem">
            <label>扣量率(%)：</label>
            @Html.TextBoxFor(m => m.RechDiscountRate, new { @class = "easyui-numberbox", min="0", max="50", @style = "width:200px;", @required = "true", @maxlength = "2" })
            只针对话费类礼品
        </div>        
        <input type="hidden" name="UserID" id="UserID" />
    
    </form>
</div>
